package com.atguigu.Example.Dao.Impl;

import com.atguigu.Example.Dao.StudentDao;
import com.atguigu.Example.Pojo.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author Cheng-02
 * @version V1.0
 * @Package com.Example.Dao.Impl
 * @date 2024/4/22 下午2:40
 */
@Repository
public class StudentDaoImpl  implements StudentDao {
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Override
    public List<Student> findAll() {
        String sql="SELECT id,name,gender,age,class as classes FROM students;";
        List<Student> students = jdbcTemplate.query(sql, new BeanPropertyRowMapper<Student>(Student.class));
        return students;
    }
}
